from django import forms

from app01 import models


class ArticleForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        for field in self.fields.values():
            field.widget.attrs["class"] = "form-control"

        self.fields.get("tags").required = False
        self.fields.get("thumbnail").required = False


    class Meta:
        model = models.Article

        fields = "__all__"

        exclude = [
                "author",
                "view_count",
                ]


class SubcategoryForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        for field in self.fields.values():
            field.widget.attrs["class"] = "form-control"

    class Meta:

        model = models.Subcategory
        fields = '__all__'



class CarouselForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        for field in self.fields.values():
            field.widget.attrs["class"] = "form-control"

    class Meta:

        model = models.Carousel
        fields = '__all__'


